package Pattern.SingletonPattern;

public class Singleton3 {//双重校验锁+volatile关键字
    private static volatile Singleton3 instance=null; //volatile防止指令重排

    public Singleton3() {
    }

    public static Singleton3 getInstance(){
        if(instance == null){
            synchronized (Singleton3.class){
                if(instance == null){
                    instance = new Singleton3();//其实是三步
                }
            }
        }
        return instance;
    }
}
